/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.matrimonybeans;

import java.math.BigDecimal;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.HashMap;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.ejb.Stateless;

/**
 *
 * @author hb
 */
@Stateless
public class Update_Services implements Update_ServicesLocal {

    Connection conn;
    boolean flag = false;
    ResultSet rs = null;

    @Override
    public Boolean Update_services_data(int id_services, String select_edition, String post_your, BigDecimal payment) {
        try {
            ConnectDB conDB = new ConnectDB();
            conn = conDB.getConnection();
            String sql_update = "Update Services set select_edition=?, post_your= ?,payment=? where  id_services=?";
            PreparedStatement pmst = conn.prepareStatement(sql_update);
            

            pmst.setString(1, select_edition);
            pmst.setString(2, post_your);
            pmst.setBigDecimal(3, payment);
            pmst.setInt(4, id_services);

            int count = 0;
            count = pmst.executeUpdate();
            if (count > 0) {
                flag = true;
            } else {
                flag = false;
            }
        } catch (SQLException ex) {
            Logger.getLogger(Update_Services.class.getName()).log(Level.SEVERE, null, ex);
        }
        return flag;
    }

    // Add business logic below. (Right-click in editor and choose
    // "Insert Code > Add Business Method")
    @Override
    public HashMap selectservices() {
        HashMap selectServ = new HashMap();
        try {
            ConnectDB conDB = new ConnectDB();
            conn = conDB.getConnection();
            String select_Charges = "Select * from Services";
            PreparedStatement pmst = conn.prepareStatement(select_Charges);
            rs = pmst.executeQuery();
             while(rs.next())
            {
                HashMap hm = new HashMap();
                hm.put("id_services", rs.getInt("id_services"));
                hm.put("select_edition", rs.getString("select_edition").trim());
                hm.put("post_your", rs.getString("post_your").trim());
                hm.put("payment", rs.getInt("payment"));
                selectServ.put(rs.getInt("id_services"),hm);
                
            }

        } catch (SQLException ex) {
            Logger.getLogger(Update_Services.class.getName()).log(Level.SEVERE, null, ex);
        }
        return selectServ;
    }

    @Override
    public ResultSet businessMethodselectservice(int id_services) {
        try {
            ConnectDB conDB = new ConnectDB();
            conn = conDB.getConnection();
            String select_Charge = "Select * from Services where id_services= ?";
            PreparedStatement pmst = conn.prepareStatement(select_Charge);
            pmst.setInt(1, id_services);
            rs = pmst.executeQuery();
        } catch (SQLException ex) {
            Logger.getLogger(Update_Services.class.getName()).log(Level.SEVERE, null, ex);
        }
        return rs;
    }

    @Override
    public Boolean businessMethodDelete(int id_services) {
        try {
            ConnectDB conDB = new ConnectDB();
            conn = conDB.getConnection();
            String delte_Charge = "Delete Services where id_services= ?";
            PreparedStatement pmst = conn.prepareStatement(delte_Charge);
            pmst.setInt(1, id_services);

            int count = 0;
            count = pmst.executeUpdate();
            if (count > 0) {
                flag = true;
            } else {
                flag = false;
            }

        } catch (SQLException ex) {
            Logger.getLogger(Update_Services.class.getName()).log(Level.SEVERE, null, ex);
        }
        return flag;


    }
}
